package org.jeecg.common.multipart.kit;


import java.nio.charset.Charset;
import java.security.MessageDigest;

public abstract class DigestKit {
    public DigestKit() {
    }

    public static byte[] sha256(String text) {
        try {
            MessageDigest digest = MessageDigest.getInstance("SHA-256");
            return digest.digest(text.getBytes(Charset.forName("UTF-8")));
        } catch (Exception var2) {
            throw new RuntimeException(var2);
        }
    }

    public static String toHexString(byte[] bytes) {
        StringBuilder hexString = new StringBuilder();
        byte[] arr$ = bytes;
        int len$ = bytes.length;

        for(int i$ = 0; i$ < len$; ++i$) {
            byte aByte = arr$[i$];
            String hex = Integer.toHexString(255 & aByte);
            if (hex.length() == 1) {
                hexString.append('0');
            }

            hexString.append(hex);
        }

        return hexString.toString();
    }

    public static String md5Hex(String text) {
        try {
            MessageDigest digest = MessageDigest.getInstance("MD5");
            byte[] bytes = digest.digest(text.getBytes(Charset.forName("UTF-8")));
            return toHexString(bytes);
        } catch (Exception var3) {
            throw new RuntimeException(var3);
        }
    }
}

